package com.niodata.dt.fs;

import com.niodata.dt.fs.http.HttpFileSystem;
import java.io.IOException;
import java.util.Map;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;

public class HttpFileSystemBuilder implements FileSystemBuilder {

  @Override
  public FileSystem createFileSystem(String user, Map<String, String> conf) throws IOException {
    Configuration config = new Configuration();
    String url = conf.get(HttpFileSystem.FS_HTTP_PROTOCOL) + "://" + conf
          .get(HttpFileSystem.FS_HTTP_HOST)
          + ":" + conf.get(HttpFileSystem.FS_HTTP_PORT);
    config.set("fs.defaultFS", url);
    config.setClass("fs.http.impl", HttpFileSystem.class, FileSystem.class);
    config.setClass("fs.https.impl", HttpFileSystem.class, FileSystem.class);
    conf.keySet().forEach(key -> {
      config.set(key, conf.get(key));
    });
    FileSystem fs = FileSystem.get(config);
    return fs;
  }
}
